import request from '../../request/request.js'

Page({
  data: {
    date: '',
    show: false,
    courseList:[],
    keywords:'',
    minDate: new Date().getTime()-1000*60*60*24*30,
  },
  onLoad: function(option){
    this.getCourseList();
  },
  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
  },
  onConfirm(event) {
    console.log(event);
    
    this.setData({
      show: false,
      date: this.formatDate(event.detail),
    });
    this.getCourseList()
  },
  getCourseList(param){
    var that=this;
    request({
      url:'course/list',
      data:{
        date:that.data.date,
        courseName:param
      },
      method:'post'
    }).then(res=>{
      this.setData({
        courseList:res.data.data
      })
    }).catch(err=>{})
  },
  onSearch(){
    this.getCourseList(this.data.keywords);
  },
  onChange(e){
    this.setData({keywords:e.detail})
  }
});